import Vue from 'vue'
import Router from 'vue-router'
import login from "@/pages/login";
import home from "@/pages/home";
import warn from '@/pages/warn/warnList'; //租赁信息
import declare from '@/pages/declare/declare';

Vue.use(Router)

const router = new Router({
  routes: [{
      path: '/',
      name: 'login',
      component: login
    }, {
      path: '/login',
      redirect: '/'
    },
    {
      path: "/home",
      component: home,
      // redirect: '/home/index',
      children: [{
          path: "warn",
          name: "warn",
          component: warn
        }, //租赁信息    
        {
          path: "independentDeclaration",
          name: "independentDeclaration",
          component: declare
        },
      ]
    }
  ]
})
//路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/')
    return next()
  // 获取token
  const tokenStr = JSON.parse(localStorage.getItem("token"));
  if (!tokenStr)
    return next('/')
  next()
})
export default router
